package com.woniuxy.amusementparkos.controller.lsy;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.amusementparkos.dto.lvd.TableDataDto;
import com.woniuxy.amusementparkos.entity.lsy.Counter;
import com.woniuxy.amusementparkos.service.lsy.CounterService;

import lombok.extern.slf4j.Slf4j;

/**
* @author Muzi
* 柜台-控制器
* 2020年4月24日下午9:31:38
*/
@Controller
@RequestMapping("/counter")
@Slf4j
public class CounterController {
	
	@Autowired
	private CounterService counterService;
	
	@RequestMapping("/getAll")
	@ResponseBody
	public TableDataDto<Counter> getAll(){
		List<Counter> counters = counterService.listAllCounter();
		//状态码0 装入数据 20L实际该从数据库查询
		TableDataDto<Counter> tdd = new TableDataDto<>(0, "", 20L, counters);
		return tdd;
	}
	
	
	/**
     * 控制器统一异常处理器
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public TableDataDto<Integer> resolveException(Exception e){
    	// 创建对象
    	TableDataDto<Integer> result = new TableDataDto<>();
    	// 设置参数
    	result.setMsg("操作异常，请联系管理员");
    	// 记录日志
    	log.error("CounterController发生严重异常："+e.getMessage()+e);
    	// 设置状态
		result.setCode(4);
    	return result;
    }
}
